#ifndef PARTMANAGER_H
#define PARTMANAGER_H

#include <QMainWindow>
#include <QCheckBox>
#include <QSqlQueryModel>
#include <QEvent>
#include <QMouseEvent>
#include <QSqlQuery>
#include <QMessageBox>
#include <QSqlError>

#include "User.h"
#include "DatabaseManager.h"

namespace Ui {
class PartManager;
}

class PartManager : public QMainWindow
{
    Q_OBJECT

public:
    explicit PartManager(QMainWindow *parent = nullptr);
    explicit PartManager(const User& user = User(), QMainWindow *parent = nullptr);
    ~PartManager();

    void initMenu();
    void initInfoManagePageMenu();
    void initAlloManagePageMenu();
protected:
    void mouseReleaseEvent(QMouseEvent *event) override;

private slots:
    void m_on_infoManage_tv_partInfoList_clicked(const QModelIndex& index);
    void m_on_infoManage_btn_add_clicked();
    void m_on_infoManage_btn_delete_clicked();
    void m_on_infoManage_btn_update_clicked();
    void m_on_infoManage_btn_find_clicked();
    void m_on_infoManage_btn_refresh_clicked();

    void m_on_allotManage_tv_noAllotPartInfoList_clicked(const QModelIndex& index);
    void m_on_allotManage_btn_allot_clicked();
    void m_on_allotManage_tbt_refresh();
private:
    Ui::PartManager *ui;

    DatabaseManager* m_DBManager;

    User m_operatorUserInfo;

    QSqlQueryModel* m_infoSqlQueryModel;
    QSqlQueryModel* m_allotSqlQueryModel;

    bool m_selectPartInfoFlag;
    qint64 m_selectPartInfoId;

    bool m_selectAllotPartInfoFlag;
    qint64 m_selectAllotPartInfoId;
};

#endif // PARTMANAGER_H
